const test = [
    {
        path: '1',
        routes: [
            {
                path: '2',
                routes: [
                    {
                        path: ['3', '4', '5']
                    }
                ]
            }
        ]
    }
]

let flatFun = (data) => {
    let result = []
    data.forEach(item => {
        const { path, routes } = item;
        if (routes) {
            result.push(...(flatFun(routes).map(item => path + item)))
        } else {
            if (Array.isArray(path)) {
                result.push(...path)
            } else {
                result.push(path)
            }
        }
    })
    return result
}

console.log(flatFun(test))